package com.jumi.microservice.controller.pdd;

import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.jwt.annon.IgnoreUrlsAnnon;
import com.jumi.microservice.dto.pdd.PddCpsUserInfoResponse;
import com.jumi.microservice.service.pdd.PddCpsService;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkOrderListIncrementGetRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Scw
 * @Date 2019-11-02 15:10
 */
@RestController
@RequestMapping("/api/pdd")
@Api(tags = {"C端-拼多多"})
public class PddCpsController {
    @Resource
    private PddCpsService pddCpsService;

    @ApiOperation("根据code获取用户登录信息")
    @GetMapping("/getInfoByCode")
    @IgnoreUrlsAnnon("/getInfoByCode")
    public ResponseResult<PddCpsUserInfoResponse> getInfoByCode(@ApiParam(name = "code", value = "授权code，grantType==authorization_code 时需要") @RequestParam("code") String code) {
        ResponseResult<PddCpsUserInfoResponse> result = new ResponseResult<>();
        result.setData(pddCpsService.getInfoByCode(code));
        return result;
    }

    @ApiOperation("充值中心")
    @PostMapping("/getRecharge")
    @IgnoreUrlsAnnon("/getRecharge")
    public ResponseResult<String> getRecharge(@ApiParam(name = "pid", value = "推广位") @RequestParam("pid") String pid, @ApiParam(name = "resource_type", value = "频道来源：4-限时秒杀,39997-充值中心, 39998-活动转链，39996-百亿补贴，40000-领券中心") @RequestParam("resource_type") Integer resourceType) {
        ResponseResult<String> result = new ResponseResult<>();
        if (resourceType == null) resourceType = 39997;
        result.setData(pddCpsService.getRecharge(pid, resourceType));
        return result;
    }

    @ApiOperation("CPS通用POST转发请求")
    @PostMapping("/cpsPostInfo")
    @IgnoreUrlsAnnon("/cpsPostInfo")
    public ResponseResult<String> cpsPostInfo(@ApiParam(name = "jsonStr", value = "JSON字符串", example = "{\"type\":\"pdd.ddk.resource.url.gen\",\"pid\":\"13843797_186973390\",\"resourceType\":\"39997\"}") @RequestParam(value = "jsonStr", required = false, defaultValue = "") String jsonStr) {
        ResponseResult<String> result = new ResponseResult<>();
        result.setData(pddCpsService.cpsPostInfo(jsonStr));
        return result;
    }
}
